package common.core.util;

import common.core.dto.LoginUserDto;

/**
 * @author liubo
 * @created 2019-12-26 14:59
 */
public class LoginUtil {

    private static ThreadLocal<LoginUserDto> user= new ThreadLocal<LoginUserDto>(){
        @Override
        protected LoginUserDto initialValue() {
            return new LoginUserDto();
        }
    };

    public static String getUsername(){
        return user.get().getUsername();
    }

    public static Long getId(){
        return user.get().getId();
    }

    public <T> T getOther() {
        return (T)user.get().getOther();
    }

    public static void init(LoginUserDto dto){
        user.set(dto);
    }

    public static LoginUserDto get(){
        return user.get();
    }

}
